// pages/myCard/myCard.js
var app=getApp()
Page({
  data:{
    page:1
  },
  couplist:function(page,that){
    var url=app.data.url
    var page1=wx.getStorageSync('page')
    //卡包列表
    wx.request({
      url: '' + url + '/shop/Coupon/MyCouponDetail',
      data: { openid: 1,page:page },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res)
        wx.setStorageSync('PageCount', res.data.PageCount);
        wx.setStorageSync('page', page)
        if (res.data.Rows.length > 0) {
          if (that.data.mlist) {
            var mlist = that.data.mlist
            var shuju = res.data.Rows
            var newlist= mlist.concat(shuju)
            that.setData({
              mlist: newlist,
              page: page,
            })
          } else {
            var shuju = res.data.Rows
            that.setData({
              mlist: shuju,
              page: page,
            })
          }
        } else {
          var mlist = that.data.mlist
          that.setData({
            infolist: mlist,
            page: page
          })
        }
      },
      error: function (res) {
        console.log(res)
      }
    })
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    var url=app.data.url
    var that=this
    that.couplist(1,that)
    //获取设备信息
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          height: res.windowHeight,
          width: res.windowWidth
        })
      }
    })
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
    wx.clearStorageSync('page')
    wx.clearStorageSync('PageCount')
  },
  onUnload:function(){
    // 页面关闭
    wx.clearStorageSync('page')
    wx.clearStorageSync('PageCount')
  },
  onReachBottom: function () {
    var that = this;
    var page = that.data.page;
    page++;
    if (wx.getStorageSync('PageCount') >= page) {
      if (wx.getStorageSync('page') == page) {
        return
      }
      else {
        that.couplist(page, that)
      }
    }
  },
})